package com.lottery.service.pc28.statisticsService.impl;

import com.lottery.dao.pc28.statisticsDao.WeekStatisticsDao;
import com.lottery.dto.ResultDto;
import com.lottery.entity.WeekStatistics;
import com.lottery.service.pc28.statisticsService.WeekStatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class WeekStatisticsServiceImpl implements WeekStatisticsService {

	@Resource
	private WeekStatisticsDao weekStatisticsDao;

	/**
	 * 每周统计 -时间统计和玩法统计
	 */
	@Override
	public ResultDto<Map<String, List<Double>>> selectWeekStatistics() {
		ResultDto<Map<String, List<Double>>> resultDto = new ResultDto<Map<String, List<Double>>>();
		// 大小单双玩法
		Map<Integer, Double> map1 = new HashMap<Integer, Double>();
		// 数字玩法
		Map<Integer, Double> map2 = new HashMap<Integer, Double>();
		// 数字组合玩法
		Map<Integer, Double> map3 = new HashMap<Integer, Double>();
		// 数字定位玩法
		Map<Integer, Double> map4 = new HashMap<Integer, Double>();
		// 猜合
		Map<Integer, Double> map5 = new HashMap<Integer, Double>();
		// 总额
		Map<Integer, Double> map6 = new HashMap<Integer, Double>();
		try {
			List<WeekStatistics> weekList = weekStatisticsDao.statisticalWeek();
			List<WeekStatistics> weekSUMList = weekStatisticsDao.statisticalSUMWeek();
			for (WeekStatistics week : weekList) {
				String playwayName = week.getPlaywayName();
				if (playwayName.equals("大小单双玩法")) {
					map1.put(week.getDate(), week.getMoney());
				} else if (playwayName.equals("数字玩法")) {
					map2.put(week.getDate(), week.getMoney());
				} else if (playwayName.equals("数字组合玩法")) {
					map3.put(week.getDate(), week.getMoney());
				} else if (playwayName.equals("数字定位玩法")) {
					map4.put(week.getDate(), week.getMoney());
				} else if (playwayName.equals("猜合")) {
					map5.put(week.getDate(), week.getMoney());
				}
			}
			for (WeekStatistics week : weekSUMList) {
				map6.put(week.getDate(), week.getMoney());
			}
			List<Double> list1 = getMap(map1);
			List<Double> list2 = getMap(map2);
			List<Double> list3 = getMap(map3);
			List<Double> list4 = getMap(map4);
			List<Double> list5 = getMap(map5);
			List<Double> list6 = getMap(map6);
			Map<String, List<Double>> resultDtomap = new HashMap<String, List<Double>>();
			resultDtomap.put("sizeDanShuang", list1);
			resultDtomap.put("number", list2);
			resultDtomap.put("digitalCombination", list3);
			resultDtomap.put("digitalPositioning", list4);
			resultDtomap.put("guesshe", list5);
			resultDtomap.put("total", list6);
			List<Map<String, List<Double>>> resultDtolist = new ArrayList<Map<String, List<Double>>>();
			resultDtolist.add(resultDtomap);
			resultDto.setList(resultDtolist);
			resultDto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			resultDto.setSuccess(false);
		}
		return resultDto;
	}

	// 解析map
	private List<Double> getMap(Map<Integer, Double> map) {
		List<Double> list = new ArrayList<Double>();
		Double money1 = 0.0;
		Double money2 = 0.0;
		Double money3 = 0.0;
		Double money4 = 0.0;
		Double money5 = 0.0;
		Double money6 = 0.0;
		Double money7 = 0.0;
		Set<Integer> keySet = map.keySet();
		boolean contain1 = keySet.contains(1);
		if (contain1) {
			money1 = money1 + map.get(1);
		} else {
			money1 = money1;
		}

		boolean contain2 = keySet.contains(2);
		if (contain2) {
			money2 = money1 + map.get(2);
		} else {
			money2 = money1;
		}

		boolean contain3 = keySet.contains(3);
		if (contain3) {
			money3 = money2 + map.get(3);
		} else {
			money3 = money2;
		}

		boolean contain4 = keySet.contains(4);
		if (contain4) {
			money4 = money3 + map.get(4);
		} else {
			money4 = money3;
		}

		boolean contain5 = keySet.contains(5);
		if (contain5) {
			money5 = money4 + map.get(5);
		} else {
			money5 = money4;
		}

		boolean contain6 = keySet.contains(6);
		if (contain6) {
			money6 = money5 + map.get(6);
		} else {
			money6 = money5;
		}

		boolean contain7 = keySet.contains(7);
		if (contain7) {
			money7 = money6 + map.get(7);
		} else {
			money7 = money6;
		}
		list.add(money1);
		list.add(money2);
		list.add(money3);
		list.add(money4);
		list.add(money5);
		list.add(money6);
		list.add(money7);
		return list;
	}

}
